package com.kingyun.gpsinspection.purificationservice.services.iam.innerservice.manage.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.kingyun.gpsinspection.purificationservice.dao.mapper.iam.manage.MaterialsMapper;
import com.kingyun.gpsinspection.purificationservice.facade.model.iam.manage.Materials;
import com.kingyun.gpsinspection.purificationservice.facade.service.iam.manage.MaterialsService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by yangsy on 2016/12/8.
 */
public class MaterialsServiceImpl implements MaterialsService {
    @Autowired
    private MaterialsMapper materialsMapper;
    @Override
    public int deleteByPrimaryKey(String materialsId) {
        return materialsMapper.deleteByPrimaryKey(materialsId);
    }

    @Override
    public int insert(Materials record) {
        return materialsMapper.insert(record);
    }

    @Override
    public int insertSelective(Materials record) {
        return materialsMapper.insertSelective(record);
    }

    @Override
    public Materials selectByPrimaryKey(String materialsId) {
        return materialsMapper.selectByPrimaryKey(materialsId);
    }

    @Override
    public int updateByPrimaryKeySelective(Materials record) {
        return materialsMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Materials record) {
        return materialsMapper.updateByPrimaryKey(record);
    }

    @Override
    public JSONObject list(Materials materials) {
        JSONObject jsonObject = new JSONObject();
        materials.setLimit( materials.getLimit() == null ? 10 : materials.getLimit() );
        materials.setOffset( materials.getOffset() == null ? 0 : materials.getOffset() );
        jsonObject.put("total",materialsMapper.queryCount(materials));
        jsonObject.put("rows", JSON.toJSON(materialsMapper.queryList(materials)));
        return jsonObject;
    }
}
